﻿using Coldairarrow.Business.MEGA;
using Coldairarrow.Entity.MEGA;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.MEGA
{
    [Route("/MEGA/[controller]/[action]")]
    public class MEGA_LeafBladeController : BaseApiController
    {
        #region DI

        public MEGA_LeafBladeController(IMEGA_LeafBladeBusiness mEGA_LeafBladeBus)
        {
            _mEGA_LeafBladeBus = mEGA_LeafBladeBus;
        }

        IMEGA_LeafBladeBusiness _mEGA_LeafBladeBus { get; }

        #endregion

        #region 获取
         /// <summary>
         /// 获取叶片信息列表
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<MEGA_LeafBladeDTO>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _mEGA_LeafBladeBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 获取绑定完关系的叶片信息列表（生成叶片二维码列表）
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<MEGA_LeafBladeDTO>> GetOverDataList(PageInput<ConditionDTO> input)
        {
            return await _mEGA_LeafBladeBus.GetOverDataListAsync(input);
        }

        /// <summary>
        /// 单个或者批量生成叶片二维码按钮
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task BuildQrCodeData(List<string> ids)
        {
            await _mEGA_LeafBladeBus.BuildQrCodeDataAsync(ids);
        }

        /// <summary>
        /// 二维码下载
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<string> DownLoadQrCodeData(IdInputDTO input)
        {
            return await _mEGA_LeafBladeBus.DownLoadQrCodeDataAsync(input);
        }

        /// <summary>
        /// 查看二维码
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<string> GetTheQrCodeData(IdInputDTO input)
        {
            return await _mEGA_LeafBladeBus.GetTheQrCodeDataAsync(input);
        }

        /// <summary>
        /// 获取叶片列表详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MEGA_LeafBlade> GetTheData(IdInputDTO input)
        {
            return await _mEGA_LeafBladeBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交
        /// <summary>
        /// 叶片新增、修改
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(MEGA_LeafBlade data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _mEGA_LeafBladeBus.AddDataAsync(data);
            }
            else
            {
                await _mEGA_LeafBladeBus.UpdateDataAsync(data);
            }
        }

        /// <summary>
        /// 叶片状态修改、批量修改
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UpdateStateData(List<StateDTO> input)
        {
            await _mEGA_LeafBladeBus.UpdateStateDataAsync(input);
        }

        /// <summary>
        /// 叶片删除、批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _mEGA_LeafBladeBus.DeleteDataAsync(ids);
        }

        /// <summary>
        /// 加工厂绑定,一个叶片只能绑定一个加工厂
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveTheFactoryData(List<MEGA_LeafBladeAndFactory> input)
        {
            await _mEGA_LeafBladeBus.SaveTheFactoryAsync(input);
        }

        /// <summary>
        /// 材料绑定
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveMaterialData(List<MEGA_LeafBladeAndMaterial> input)
        {
            await _mEGA_LeafBladeBus.SaveMaterialDataAsync(input);
        }

        /// <summary>
        /// 加工人绑定
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveThePeopleData(List<MEGA_LeafBladeAndWorker> input)
        {
            await _mEGA_LeafBladeBus.SaveThePeopleDataAsync(input);
        }


        #endregion
    }
}